package com.example;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
public class MyBatisExample {
    public static void main(String[] args) {
        // Load MyBatis configuration file
        String resource = "mybatis-config.xml";
        InputStream inputStream = MyBatisExample.class.getClassLoader().getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        // Open a new session
        try (SqlSession session = sqlSessionFactory.openSession()) {
            // Fetch the user by ID using selectOne
            User user = session.selectOne("UserMapper.selectUserById", 1);
            System.out.println(user);
        }
    }
}
